// ==UserScript== // @name My Green Dollar Message // @namespace chatGPTFucker // @version 0.0.1 // @description 实现类似this.$message的效果 // @author chatGPTFucker // @match https://www.sogou.com/dollarmsg // @grant GM_setClipboard // @icon data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA1MTIgNTEyIj48IS0tISBGb250IEF3ZXNvbWUgUHJvIDYuNC4wIGJ5IEBmb250YXdlc29tZSAtIGh0dHBzOi8vZm9udGF3ZXNvbWUuY29tIExpY2Vuc2UgLSBodHRwczovL2ZvbnRhd2Vzb21lLmNvbS9saWNlbnNlIChDb21tZXJjaWFsIExpY2Vuc2UpIENvcHlyaWdodCAyMDIzIEZvbnRpY29ucywgSW5jLiAtLT48cGF0aCBkPSJNMjU2IDUxMkEyNTYgMjU2IDAgMSAwIDI1NiAwYTI1NiAyNTYgMCAxIDAgMCA1MTJ6TTM2OSAyMDlMMjQxIDMzN2MtOS40IDkuNC0yNC42IDkuNC0zMy45IDBsLTY0LTY0Yy05LjQtOS40LTkuNC0yNC42IDAtMzMuOXMyNC42LTkuNCAzMy45IDBsNDcgNDdMMzM1IDE3NWM5LjQtOS40IDI0LjYtOS40IDMzLjkgMHM5LjQgMjQuNiAwIDMzLjl6Ii8+PC9zdmc+ // ==/UserScript== (function() { // 添加 style 元素, 让页面空白 const style = document.createElement('style'); style.innerHTML = ` center, hr { display: none; } `; document.head.appendChild(style); // My Message 实现类似this.$message的效果 class Message { constructor() { this.container = document.createElement('div'); this.container.id = 'messageContainer'; this.container.style.position = 'fixed'; this.container.style.top = '20px'; this.container.style.left = '50%'; this.container.style.transform = 'translateX(-50%)'; this.container.style.display = 'flex'; this.container.style.alignItems = 'center'; this.container.style.justifyContent = 'center'; this.container.style.zIndex = '9999'; document.body.appendChild(this.container); } show(message, iconType) { const p = document.createElement('p'); p.style.margin = '10px'; p.style.padding = '10px'; p.style.backgroundColor = '#f5f5f5'; p.style.borderRadius = '4px'; p.style.display = 'flex'; p.style.alignItems = 'center'; let icon; if (iconType === 'tick') { icon = document.createElement('span'); icon.style.width = '16px'; icon.style.height = '16px'; icon.style.backgroundColor = 'green'; icon.style.borderRadius = '50%'; icon.style.marginRight = '10px'; const checkmark = document.createElementNS("http://www.w3.org/2000/svg", "svg"); checkmark.setAttribute("viewBox", "0 0 24 24"); checkmark.setAttribute("width", "16"); checkmark.setAttribute("height", "16"); const path = document.createElementNS("http://www.w3.org/2000/svg", "path"); path.setAttribute("d", "M9 16.2l-3.6-3.6c-.8-.8-.8-2 0-2.8s2-.8 2.8 0L9 11.6l6.2-6.2c.8-.8 2-.8 2.8 0s.8 2 0 2.8L11.8 16.2c-.4.4-.8.6-1.3.6-.5 0-.9-.2-1.3-.6z"); path.setAttribute("fill", "white"); checkmark.appendChild(path); icon.appendChild(checkmark); } else { icon = document.createElement('span'); icon.style.width = '16px'; icon.style.height = '16px'; icon.style.backgroundColor = 'green'; icon.style.borderRadius = '50%'; icon.style.marginRight = '10px'; } p.appendChild(icon); const text = document.createTextNode(message); p.appendChild(text); this.container.appendChild(p); setTimeout(() => { this.container.removeChild(p); }, 3000); } } // 使用示例 const message = new Message(); // message.show('这是一条消息提示'); message.show('这是一条消息提示', 'tick'); // 显示绿色勾图标的消息提示 })();